home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10515 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Function Offsets
  5. Date: Mon, 18 Mar 96 12:11:49 GMT
  6. Organization: none
  7. Message-ID: <827151109snz@genesis.demon.co.uk>
  8. References: <4ih3p4$4gn@cloner4.netcom.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ih3p4$4gn@cloner4.netcom.com>
  15.            fame1@ix.netcom.com "Matt Kittleson" writes:
  16.  
  17. >Is this the best way to get the offset of a function?
  18.  
  19. The 'value' of the identifier main gives you a pointer to the main function.
  20. However functions aren't objects and you can't perform pointer arithmetic
  21. on function pointers.
  22.  
  23. >void main()
  24.  
  25. main returns int in C.
  26.  
  27. >{
  28. >void funct1()
  29. >
  30. >some code here...blah...blah...blah
  31. >
  32. >}
  33. >
  34. >Would i then be able to printf the address out?
  35.  
  36. printf doesn't provide a portable way of printing function pointers.
  37.  
  38. >Then if I loaded the
  39. >program by just malloc'n the memory, jump to the function by
  40. >subtracting offsets?  I have been meaning to try it, but have had
  41. >little time.
  42.  
  43. This may work on a few systems (e.g. by casting the pointer returned by
  44. malloc to an appropriate function pointer and calling through that) but
  45. such operations are illegal in C (they result in undefined behaviour).
  46. On many systems code has to go in a code segment so memory allocated by
  47. malloc would be totally inappropriate.
  48.  
  49. >Any other info on either this or dynamic linking in general would be
  50. >greatly appreaciated.
  51.  
  52. If your system supports dynamic linking it will provide some sort of
  53. interface to call up those facilities. However this is highly system
  54. dependent so you should refer to your system's documentation or failing
  55. that a newsgroup related to your particular system.
  56.  
  57. -- 
  58. -----------------------------------------
  59. Lawrence Kirby | fred@genesis.demon.co.uk
  60. Wilts, England | 70734.126@compuserve.com
  61. -----------------------------------------
  62.